package com.o2o.utils

import java.sql.Date
import java.text.SimpleDateFormat

import org.joda.time.DateTime

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2019/1/8 22:35
  * @ Param:  $param$
  * @ Description:
  */
object time_stamp_util {
  def main(args: Array[String]): Unit = {

  }

  def convertTimeStamp2Date(timestamp: Long): Int = {
    val time = new DateTime(timestamp)
    time.toInstant.toString.split("-")(2).toInt
  }

  def time2day(time: String): Int = {
    var sdf: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
    var date: String = sdf.format(new Date((time.toLong * 1000l)))
    date.toString.split("-")(2).toInt
  }


  def timeStamp2yyMM(time: String): String = {
    var sdf: SimpleDateFormat = new SimpleDateFormat("yyyyMM")
    var date: String = sdf.format(new Date((time.toLong * 1000l)))
    date
    //    date.toString.split("-")(2).toInt
  }

  /**
    * 两个时间戳间隔天数
    *
    * @param timeStamp1
    * @param timeStamp2
    * @return
    */
  def time2DifferDay(timeStamp1: Long, timeStamp2: Long): Long = {
    ((timeStamp2 - timeStamp1) / (24 * 3600)).toInt
  }

  def timeStamp2MMdd(time: Long): String = {
    var sdf: SimpleDateFormat = new SimpleDateFormat("yyyyMMdd")
    var date: String = sdf.format(new Date((time.toLong * 1000l)))
    date.substring(5)
    //    date.toString.split("-")(2).toInt
  }

  /**
    *
    * @param time
    * @return
    */
  def timeStamp2yyMMdd(time: String): String = {
    val sdf: SimpleDateFormat = new SimpleDateFormat("yyyyMMdd")
    val date: String = sdf.format(new Date((time.toLong * 1000l)))
    date
  }

}
